package io.renren.modules.ProjectControl;

import io.renren.modules.ProjectControl.Service.ExeCommandP1;
import io.renren.modules.ProjectControl.Service.ExeCommandP3;
import io.renren.modules.ProjectControl.Service.ExeCommandService.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

import static java.lang.Thread.sleep;

@RestController

@RequestMapping("/subProjectControl")
public class ControlCenter {

    @Autowired
    ExeServiceP4 E4;
    @Autowired
    ExeServiceP2 E2;

    @Autowired
    ExeServiceP3 E3;

    @Autowired
    ExeServiceP1 E1;

    @Autowired
    ExeServiceNginx N;

    @PostMapping("/StartP4")
    public  void StartP4() throws IOException, InterruptedException {
    E4.Start("cmd /c start D:\\Program\\TestDEMO\\BootScriptP4.bat");
    }

    @PostMapping("/ShutP4")
    public  void ShutdownP4() throws IOException, InterruptedException {
        E4.Stop("cmd /c start D:\\Program\\TestDEMO\\ShutScriptP4.bat");
    }
    @GetMapping("/StatusP4")
    public  String StatusP4() throws IOException, InterruptedException {
        return E4.Status();
    }
//***************************************************************************************************************


    @PostMapping("/StartP2")
    public  void StartP2() throws IOException, InterruptedException {
        E2.Start("cmd /c start D:\\Program\\TestDEMO\\BootScriptP2.bat");
    }
    @PostMapping("/ShutP2")
    public  void ShutdownP2() throws IOException, InterruptedException {
        E2.Stop("cmd /c start D:\\Program\\TestDEMO\\ShutScriptP2.bat");
    }
    @GetMapping("/StatusP2")
    public  String StatusP2() throws IOException, InterruptedException {
        return E2.Status();
    }



    @PostMapping("/StartP3")
    public  void StartP3() throws IOException, InterruptedException {
        E3.Start("cmd /c start D:\\Program\\TestDEMO\\BootScriptP3.bat");
    }
    @PostMapping("/ShutP3")
    public  void ShutdownP3() throws IOException, InterruptedException {
        E3.Stop("cmd /c start D:\\Program\\TestDEMO\\ShutScriptP3.bat");
    }
    @GetMapping("/StatusP3")
    public  String StatusP3() throws IOException, InterruptedException {
        return E3.Status();
    }

    //控制工序排产启停

    @PostMapping("/StartP3-1")
    public  void StartP3_1() throws IOException, InterruptedException {
        E3.Start("cmd /c start D:\\Program\\TestDEMO\\BootScriptP3.bat");
    }
    @PostMapping("/ShutP3-1")
    public  void ShutdownP3_1() throws IOException, InterruptedException {
        E3.Stop("cmd /c start D:\\Program\\TestDEMO\\ShutScriptP3.bat");
    }
    @GetMapping("/StatusP3-1")
    public  String StatusP3_1() throws IOException, InterruptedException {
        return E3.Status();
    }






    @PostMapping("/StartP1")
    public  void StartP1() throws IOException, InterruptedException {
        E1.Start("cmd /c start D:\\Program\\TestDEMO\\BootScriptP1.bat");
    }
    @PostMapping("/ShutP1")
    public  void ShutdownP1() throws IOException, InterruptedException {
        E1.Stop("cmd /c start D:\\Program\\TestDEMO\\ShutScriptP1.bat");
    }
    @GetMapping("/StatusP1")
    public  String StatusP1() throws IOException, InterruptedException {
        return E1.Status();
    }




    @PostMapping("/StartNginx")
    public String StartNginx() throws IOException, InterruptedException {
        N.Start("cmd /c start D:\\Program\\TestDEMO\\BootScriptNginx.bat");
        return null;
    }


}
